// 登录用户校验
import Mock from 'mockjs'
let userInfo = {
    "error_code": 0,
    "data": [{
      "id": '1',
      "usertitle": "管理员",
      "username": "admin",
      "password": "123456",
      "token": "12345",
    },
    {
      "id": '2',
      "usertitle": "超级管理员",
      "username": "root",
      "password": "root",
      "token": "23456",
    }
    ]
  }
  
  Mock.mock(/\/api\/user\/login/, 'post', (data) => {
    var body = JSON.parse(data.body);
    var auth = false;
    var users = userInfo.data;
    for (let i = 0; i < users.length; i++) {
      if (users[i].username == body.username && users[i].password == body.password) {
        auth = true;
      }
    }
    if (auth) {
      return {
        message: '登录成功',
        user: {
          username: body.username
        }
      }
    }else{
      return{
        message: '用户名或密码错误'
      }
    }
  })